package com.work.demo.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service("RedisStorageStrServiceImpl")
public class RedisStorageStrServiceImpl implements RedisStorageService{

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public void add(String key, String value) {
        redisTemplate.boundValueOps(key).set(value);
    }

    @Override
    public String getValue(String key) {
        return redisTemplate.boundValueOps(key).get();
    }

    @Override
    public boolean del(String key) {
        return Boolean.TRUE.equals(redisTemplate.delete(key));
    }

    @Override
    public boolean expired(String key, Long time, TimeUnit timeUnit) {
        return Boolean.TRUE.equals(redisTemplate.expire(key, time, timeUnit));
    }
}
